package com.cat.enumerate;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/longest-palindrome-after-substring-concatenation-i/description/?envType=problem-list-v2&envId=enumerationhttps://leetcode.cn/problems/longest-palindrome-after-substring-concatenation-i/description/?envType=problem-list-v2&envId=enumeration
 * @create 2025/9/21 18:49
 * @since JDK17
 */

public class Solution12 {
    List<String> list1 = new ArrayList<>(), list2 = new ArrayList<>();
    void get(String s, List<String> list) {
        int n = s.length();
        for (int len = 1; len <= n; len++) {
            for (int i = 0; i + len <= n; i++) {
                list.add(s.substring(i, i + len));
            }
        }
    }
    int check(String s) {
        int i = 0, j = s.length() - 1;
        while (i < j) {
            if (s.charAt(i++) != s.charAt(j--)) {
                return 0;
            }
        }
        return 1;
    }

    public int longestPalindrome(String s, String t) {
        get(s, list1);
        get(t, list2);
        list1.add("");
        list2.add("");
        int ans = 0, n = list1.size(), m = list2.size();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                ans += check(list1.get(i) + list2.get(j));
            }
        }

        return ans;
    }
}
